﻿$.extend(validatePrompt, {
	email : {
		onFocus : "请输入常用的邮箱，将用来找回密码、接收订单信息等",
		succeed : "",
		isNull : "请输入邮箱",
		error : {
			beUsed : "该邮箱已被使用，请更换其它邮箱",
			badFormat : "请输入有效的邮箱地址",
			badLength : "您填写的邮箱过长，邮箱地址只能在50个字符以内"
		}
	},
	password : {
		onFocus : "6-20位字符，可使用字母、数字或符号的组合",
		succeed : "",
		isNull : "请输入密码",
		error : {
			badLength : "密码长度只能在6-20位字符之间",
			badFormat : "密码只能由英文、数字及标点符号组成",
			simplePwd : "密码太弱，有被盗风险，建议设置多种字符组成的复杂密码"
		}
	},
	confirmPassword : {
		onFocus : "请再次输入密码",
		succeed : "",
		isNull : "请输入密码",
		error : {
			badLength : "密码长度只能在6-20位字符之间",
			badFormat2 : "两次输入密码不一致",
			badFormat1 : "密码只能由英文、数字及标点符号组成"
		}
	},
	name : {
		onFocus : "2-20位字符，可由中文或英文组成",
		succeed : "",
		isNull : "请输入联系人姓名",
		error : {
			badLength : "联系人姓名长度只能在2-20位字符之间",
			badFormat : "联系人姓名只能由中文或英文组成"
		}
	},
	phone : {
		onFocus : "请填写联系人常用的电话，以便于我们联系，如：0527-88105500",
		succeed : "",
		isNull : "请输入联系人固定电话",
		error : "电话格式错误，请重新输入"
	},
	mobile : {
		onFocus : "输入联系人手机号",
		succeed : "",
		isNull : "输入联系人手机号",
		error : "手机号格式错误，请重新输入"
	},
	qq : {
		onFocus : "请填写联系人常用的QQ，以便于我们联系，如：888888",
		succeed : "",
		isNull : "请输入联系人常用的QQ",
		error : "QQ格式错误，请重新输入"
	},
	companyName : {
		onFocus : "请填写工商局注册的全称。4-40位字符，可由中英文、数字及“_”、“-”、()、（）组成",
		succeed : "",
		isNull : "请输入公司名称",
		error : {
			badLength : "公司名称长度只能在4-40位字符之间",
			badFormat : "公司名称只能由中文、英文、数字及“_”、“-”、()、（）组成"
		}
	},
	commerceNo : {
		onFocus : "请填写工商局注册的工商登记号。15位字符组成",
		succeed : "",
		isNull : "请填写工商局注册的工商登记号",
		error : {
			badLength : "工商登记号长度只能是15位数字组成",
			badFormat : "工商登记号长度只能是15位数字组成"
		}
	},
	companyarea : {
		onFocus : "请选择公司所在地",
		succeed : "",
		isNull : "请选择公司所在地",
		error : ""
	},
	address : {
		onFocus : "请详细填写公司经营地址　如：北京市海淀区苏州街20号银丰大厦B座3层",
		succeed : "",
		isNull : "请输入公司地址",
		error : {
			badLength : "公司地址长度只能在4-50位字符之间",
			badFormat : "公司地址只能由中文、英文、数字及“_”、“-”、()、（）、#组成"
		}
	},
	website : {
		onFocus : "如：http://www.360buy.com",
		succeed : "",
		isNull : "请输入公司公司网址",
		error : {
			badLength : "公司网址长度只能在80位字符之内",
			badFormat : "公司网址格式不正确。应如：http://www.360buy.com"
		}
	},
	zipcode : {
		onFocus : "请选择公司所在地邮编",
		succeed : "",
		isNull : "请选择公司所在地邮编",
		error : {
			badLength : "邮编格式不正确。应如：201112",
			badFormat : "邮编格式不正确。应如：201112"
		}
	}
});

$
		.extend(
				validateFunction,
				{

					email : function(option) {
						var format = validateRules.isEmail(option.value);
						var format2 = validateRules.betweenLength(option.value,
								0, 50);
						if (!format) {
							validateSettings.error.run(option,
									option.prompts.error.badFormat);
						} else {
							if (!format2) {
								validateSettings.error.run(option,
										option.prompts.error.badLength);
							} else {
								if (!emailstate || emailold != option.value) {
									if (emailold != option.value) {
										emailold = option.value;
										option.errorEle
												.html("<span style='color:#999'>检验中……</span>");
										$
												.getJSON(
														"checkUserName.action?email="
																+ option.value,
														function(date) {
															if (date == 0) {
																if ($("#email_linker")) {
																	$(
																			"#email_linker")
																			.text(
																					option.value);
																}

																validateSettings.succeed
																		.run(option);
																emailstate = true;
															} else {
																validateSettings.error
																		.run(
																				option,
																				option.prompts.error.beUsed);
																emailstate = false;
															}
														})
									} else {
										validateSettings.error.run(option,
												option.prompts.error.beUsed);
										emailstate = false;
									}
								} else {
									if ($("#email_linker")) {
										$("#email_linker").text(option.value);
									}
									validateSettings.succeed.run(option);
								}
							}
						}
					},
					password : function(option) {

						var str1 = option.value;
						var str2 = $("#confirmPassword").val();
						var format = validateRules.isPwd(option.value);
						var length = validateRules.betweenLength(option.value,
								6, 20);
						$("#pwdstrength").hide();
						if (!length && format) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else if (!length && !format) {
							validateSettings.error.run(option,
									option.prompts.error.badFormat);
						} else if (length && !format) {
							validateSettings.error.run(option,
									option.prompts.error.badFormat);
							/*
							 * } else if (validateRules.simplePwd(str1)) {
							 * validateSettings.error.run(option,
							 * option.prompts.error.simplePwd);
							 */
						} else {
							validateSettings.succeed.run(option);
							validateFunction.pwdstrength();
						}
						if (str2 == str1) {
							$("#confirmPassword").focus();
						}
					},
					confirmPassword : function(option) {
						var str1 = option.value;
						var str2 = $("#password").val();
						var length = validateRules.betweenLength(option.value,
								6, 20);
						var format2 = validateRules.isPwd2(str1, str2);
						var format1 = validateRules.isPwd(str1);
						if (!length) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else {
							if (!format1) {
								validateSettings.error.run(option,
										option.prompts.error.badFormat1);
							} else {
								if (!format2) {
									validateSettings.error.run(option,
											option.prompts.error.badFormat2);
								} else {
									validateSettings.succeed.run(option);
								}
							}
						}
					},
					name : function(option) {
						var length = validateRules.betweenLength(option.value
								.replace(/[^\x00-\xff]/g, "**"), 2, 20);
						var format = validateRules.isRealName(option.value);
						if (!length) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else {
							if (!format) {
								validateSettings.error.run(option,
										option.prompts.error.badFormat);
							} else {
								validateSettings.succeed.run(option);
							}
						}
					},
					phone : function(option) {
						var format = validateRules.isTel(option.value);
						if (!format) {
							validateSettings.error.run(option,
									option.prompts.error);
						} else {
							validateSettings.succeed.run(option);
						}
					},
					mobile : function(option) {
						var format = validateRules.isMobile(option.value);
						if (!format) {
							validateSettings.error.run(option,
									option.prompts.error);
						} else {
							validateSettings.succeed.run(option);
						}
					},
					qq : function(option) {
						var length = validateRules.betweenLength(option.value
								.replace(/[^\x00-\xff]/g, "**"), 2, 20);
						var format = validateRules.isNum1(option.value);
						if (!length) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else {
							if (!format) {
								validateSettings.error.run(option,
										option.prompts.error.badFormat);
							} else {
								validateSettings.succeed.run(option);
							}
						}
					},
					companyName : function(option) {
						var length = validateRules.betweenLength(option.value
								.replace(/[^\x00-\xff]/g, "**"), 4, 40);
						var format = validateRules.isCompanyname(option.value);
						if (!length) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else {
							if (!format) {
								validateSettings.error.run(option,
										option.prompts.error.badFormat);
							} else {
								validateSettings.succeed.run(option);
							}
						}
					},
					companyarea : function(option) {
						var bool = (option.value == -1);
						if (bool) {
							validateSettings.isNull.run(option, "");
						} else {
							validateSettings.succeed.run(option);
						}
					},
					address : function(option) {
						var length = validateRules.betweenLength(option.value
								.replace(/[^\x00-\xff]/g, "**"), 4, 50);
						var format = validateRules.isCompanyaddr(option.value);
						if (!length) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else {
							if (!format) {
								validateSettings.error.run(option,
										option.prompts.error.badFormat);
							} else {
								validateSettings.succeed.run(option);
							}
						}
					},
					website : function(option) {
						var length = validateRules.betweenLength(option.value,
								0, 80);
						var format = validateRules.isCompanysite(option.value);
						if (!length) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else {
							if (!format) {
								validateSettings.error.run(option,
										option.prompts.error.badFormat);
							} else {
								validateSettings.succeed.run(option);
							}
						}
					},
					zipcode : function(option) {
						var format = validateRules.isZipcode(option.value);
						if (!format) {
							validateSettings.error.run(option,
									option.prompts.error.badFormat);
						} else {
							validateSettings.succeed.run(option);
						}
					},
					commerceNo : function(option) {
						var length = validateRules.betweenLength(option.value
								.replace(/[^\x00-\xff]/g, "**"), 15, 15);
						var format = validateRules.fullNumberName(option.value);
						if (!length) {
							validateSettings.error.run(option,
									option.prompts.error.badLength);
						} else {
							if (!format) {
								validateSettings.error.run(option,
										option.prompts.error);
							} else {
								validateSettings.succeed.run(option);
								/*option.errorEle
										.html("<span style='color:#999'>检验中……</span>");
								$.getJSON("checkCommerceNo.action?commerceNo="
										+ option.value, function(date) {
									if (date == 0) {
										if ($("#commerceNo_linker")) {
											$("#commerceNo_linker").text(
													option.value);
										}

										validateSettings.succeed.run(option);
										emailstate = true;
									} else {
										validateSettings.error.run(option,
												option.prompts.error.beUsed);
										emailstate = false;
									}
								})*/
							}
						}

					},
					emRegCompany_validate : function() {

						$("#email").jdValidate(validatePrompt.email,
								validateFunction.email, true);
						$("#password").jdValidate(validatePrompt.password,
								validateFunction.password, true)
						$("#confirmPassword").jdValidate(
								validatePrompt.confirmPassword,
								validateFunction.confirmPassword, true);
						$("#name").jdValidate(validatePrompt.name,
								validateFunction.name, true);
						$("#phone").jdValidate(validatePrompt.phone,
								validateFunction.phone, true);
						$("#mobile").jdValidate(validatePrompt.mobile,
								validateFunction.mobile, true);
						$("#qq").jdValidate(validatePrompt.qq,
								validateFunction.qq, true);
						$("#companyName").jdValidate(
								validatePrompt.companyName,
								validateFunction.companyName, true);
						// $("#hncompanyarea").jdValidate(validatePrompt.companyarea,
						// validateFunction.companyarea, true);
						$("#address").jdValidate(validatePrompt.address,
								validateFunction.address, true);
						$("#zipcode").jdValidate(validatePrompt.zipcode,
								validateFunction.zipcode, true);
						$("#website").jdValidate(validatePrompt.website,
								validateFunction.website, true);
						$("#commerceNo").jdValidate(validatePrompt.commerceNo,
								validateFunction.commerceNo, true);

						return validateFunction.FORM_submit([ "#email",
								"#password", "#confirmPassword", "#name",
								"#phone", "#mobile", "#qq", "#companyName",
								"#address", "#website", "#zipcode",
								"#commerceNo" ]);
					},

					updateEntUserInfo_validate : function() {

						$("#name").jdValidate(validatePrompt.name,
								validateFunction.name, true);
						$("#phone").jdValidate(validatePrompt.phone,
								validateFunction.phone, true);
						$("#mobile").jdValidate(validatePrompt.mobile,
								validateFunction.mobile, true);
						$("#qq").jdValidate(validatePrompt.qq,
								validateFunction.qq, true);
						$("#companyName").jdValidate(
								validatePrompt.companyName,
								validateFunction.companyName, true);
						/*
						 * $("#hncompanyarea").jdValidate(
						 * validatePrompt.companyarea,
						 * validateFunction.companyarea, true);
						 */
						$("#address").jdValidate(validatePrompt.address,
								validateFunction.address, true);
						$("#zipcode").jdValidate(validatePrompt.zipcode,
								validateFunction.zipcode, true);
						$("#website").jdValidate(validatePrompt.website,
								validateFunction.website, true);
						$("#commerceNo").jdValidate(validatePrompt.commerceNo,
								validateFunction.commerceNo, true);

						return validateFunction.FORM_submit([ "#name",
								"#phone", "#mobile", "#qq", "#companyName",
								"#address", "#website", "#zipcode",
								"#commerceNo" ]);
					}
				});

$("#email").jdValidate(validatePrompt.email, validateFunction.email);
$("#password").bind("keyup", function() {
	validateFunction.pwdstrength();
}).jdValidate(validatePrompt.password, validateFunction.password)
$("#confirmPassword").jdValidate(validatePrompt.confirmPassword,
		validateFunction.confirmPassword);
$("#name").jdValidate(validatePrompt.name, validateFunction.name);
$("#mobile").jdValidate(validatePrompt.mobile, validateFunction.mobile);
$("#phone").jdValidate(validatePrompt.phone, validateFunction.phone);
$("#qq").jdValidate(validatePrompt.qq, validateFunction.qq);
$("#authcode").jdValidate(validatePrompt.authcode, validateFunction.authcode);
$("#companyName").jdValidate(validatePrompt.companyName,
		validateFunction.companyName);
$("#address").jdValidate(validatePrompt.address, validateFunction.address);
$("#website").jdValidate(validatePrompt.website, validateFunction.website);
$("#zipcode").jdValidate(validatePrompt.zipcode, validateFunction.zipcode);
$("#zipcode").jdValidate(validatePrompt.zipcode, validateFunction.zipcode);
$("#commerceNo").jdValidate(validatePrompt.commerceNo,
		validateFunction.commerceNo);
$("#viewpwd").bind("click", function() {
	if ($(this).attr("checked") == true) {
		validateFunction.showPassword("text");
		$("#o-password").addClass("pwdbg");
	} else {
		validateFunction.showPassword("password");
		$("#o-password").removeClass("pwdbg");
	}
});

$("#registsubmit").click(function() {

	var flag = validateFunction.emRegCompany_validate();
	if (flag) {
		$("#registEntUser").submit();
	}
})

$("#updateSubmit").click(function() {

	var flag = validateFunction.updateEntUserInfo_validate();
	if (flag) {
		$("#updateEntUserInfo").submit();
	}
})

$(function() {

	refreshAreas(1, 0);

	function refreshAreas(level, parentId) {
		var myname;

		if (level == 1) {
			myname = "companycity";
			if (parentId == -1) {
				$("#companycity").empty();
				$("#companycity").append(
						"<option value=\"-1\" selected>请选择</option>");
				$("#companycity").css({
					"width" : "auto"
				});
				$("#companyarea").empty();
				$("#companyarea").append(
						"<option value=\"-1\" selected>请选择</option>");
				$("#companyarea").css({
					"width" : "auto"
				});
			}
		} else {
			myname = "companyarea";
			if (parentId == -1) {
				$("#companyarea").empty();
				$("#companyarea").append(
						"<option value=\"-1\" selected>请选择</option>");
				$("#companyarea").css({
					"width" : "auto"
				});
			}
		}
		if (parentId > 0) {
			$.getJSON("AjaxService.aspx?action=GetAreas&level=" + level
					+ "&parentId=" + parentId, function(result) {
				if (result.Areas != null) {
					$("#" + myname).empty();
					$("#" + myname).append(
							"<option value=\"-1\"  selected>请选择</option>");
					for ( var i = 0; i < result.Areas.length; i++) {
						var area = result.Areas[i];
						$("#" + myname).append(
								"<option  value=\"" + area.Id + "\">"
										+ area.Name + "</option>");
					}
					$("#" + myname).css({
						"width" : "Auto"
					});
				}
			});
		}
	}

	$("#companyprovince").change(function() {
		refreshAreas(1, parseInt($(this).val()));
		$("#companyarea").empty();
		$("#companyarea").append("<option value=\"-1\" selected>请选择</option>");
	});

	$("#companycity").change(function() {
		refreshAreas(2, parseInt($(this).val()));
	});
})

function verc() {
	$("#JD_Verification1").click();
}